package cn.edu.sgu.www.mhxysy.controller.chongwu;

import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.dto.chongwu.ChongwuNeidanDTO;
import cn.edu.sgu.www.mhxysy.entity.chongwu.ChongwuNeidan;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.chongwu.ChongwuNeidanService;
import cn.edu.sgu.www.mhxysy.vo.chongwu.ChongwuNeidanVO;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "宠物内丹管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@Validated
@RestController
@RequestMapping(path = "/chongwu_neidan", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class ChongwuNeidanController {

	private final ChongwuNeidanService chongwuNeidanService;

	@Autowired
	public ChongwuNeidanController(ChongwuNeidanService chongwuNeidanService) {
		this.chongwuNeidanService = chongwuNeidanService;
	}

	@ApiOperation("内丹共鸣")
	@RequestMapping(value = "/resonate", method = RequestMethod.POST)
	public JsonResult<Void> resonate(
			@ApiParam(name = "neidanId", value = "内丹ID", required = true)
			@NotBlank(message = "内丹ID不能为空") String neidanId) {
		chongwuNeidanService.resonate(neidanId);

		return JsonResult.success("共鸣成功");
	}

	@ApiOperation("内丹遗忘")
	@RequestMapping(value = "/forget", method = RequestMethod.POST)
	public JsonResult<Void> forget(@Validated ChongwuNeidanDTO chongwuNeidanDTO) {
		chongwuNeidanService.forget(chongwuNeidanDTO);

		return JsonResult.success(CustomMessages.OPERATE_SUCCESS);
	}

	@ApiOperation("内丹提升")
	@RequestMapping(value = "/improve", method = RequestMethod.POST)
	public JsonResult<Void> improve(@Validated ChongwuNeidanDTO chongwuNeidanDTO) {
		chongwuNeidanService.improve(chongwuNeidanDTO);

		return JsonResult.success(CustomMessages.OPERATE_SUCCESS);
	}

	@ApiOperation("内丹领悟")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "chongwuId", value = "宠物ID", readOnly = true),
			@ApiImplicitParam(name = "location", value = "镶嵌位置", readOnly = true)
	})
	@RequestMapping(value = "/comprehend", method = RequestMethod.POST)
	public JsonResult<Void> comprehend(
			@NotBlank(message = CustomMessages.CHONGWU_ID_NOT_NULL) String chongwuId,
			@NotNull(message = "镶嵌位置" + CustomMessages.NOT_NULL) Integer location) {
		chongwuNeidanService.comprehend(chongwuId, location);

		return JsonResult.success("领悟成功");
	}

	@ApiOperation("重置共鸣")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "neidanId", value = "高级内丹ID", readOnly = true),
			@ApiImplicitParam(name = "resonanceId", value = "低级内丹类型ID", readOnly = true)
	})
	@RequestMapping(value = "/resetResonate", method = RequestMethod.POST)
	public JsonResult<Void> resetResonate(
			@NotBlank(message = "高级内丹不能为空") String neidanId,
			@NotNull(message = "低级内丹不能为空") Integer resonanceId) {
		chongwuNeidanService.resetResonate(neidanId, resonanceId);

		return JsonResult.success("共鸣成功");
	}

	@ApiOperation("学习内丹")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "chongwuId", value = "宠物ID", readOnly = true),
			@ApiImplicitParam(name = "location", value = "镶嵌位置", readOnly = true),
			@ApiImplicitParam(name = "neidanId", value = "内丹类型ID", readOnly = true)
	})
	@RequestMapping(value = "/study", method = RequestMethod.POST)
	public JsonResult<Void> study(
			@NotBlank(message = "宠物ID不能为空") String chongwuId,
			@NotNull(message = "镶嵌位置不能为空") Integer location,
			@NotNull(message = "内丹类型不能为空") Integer neidanId) {
		chongwuNeidanService.study(chongwuId, location, neidanId);

		return JsonResult.success("学习成功");
	}

	@ApiOperation("查询高级内丹共鸣的内丹个数")
	@RequestMapping(value = "/selectResonateCount", method = RequestMethod.GET)
	public JsonResult<Long> selectResonateCount(
			@ApiParam(name = "neidanId", value = "内丹ID", required = true)
			@NotBlank(message = "内丹" + CustomMessages.ID_NOT_NULL) String neidanId) {
		Long count = chongwuNeidanService.selectResonateCount(neidanId);

		return JsonResult.success(null, count);
	}

	@ApiOperation("查询宠物内丹详情")
	@RequestMapping(value = "/selectDetails", method = RequestMethod.GET)
	public JsonResult<ChongwuNeidanVO> selectDetails(
			@ApiParam(name = "neidanId", value = "内丹ID", required = true)
			@NotBlank(message = "内丹" + CustomMessages.ID_NOT_NULL) String neidanId) {
		ChongwuNeidanVO neidanVO = chongwuNeidanService.selectDetails(neidanId);

		return JsonResult.success(null, neidanVO);
	}

	@ApiOperation("查询宠物内丹列表")
	@RequestMapping(value = "/selectList", method = RequestMethod.GET)
	public JsonResult<List<ChongwuNeidan>> selectList(ChongwuNeidanDTO neidanDTO) {
		List<ChongwuNeidan> list = chongwuNeidanService.selectList(neidanDTO);

		return JsonResult.success(null, list);
	}

	@ApiOperation("查询共鸣的宠物内丹列表")
	@RequestMapping(value = "/selectResonates", method = RequestMethod.GET)
	public JsonResult<List<String>> selectResonates(
			@ApiParam(name = "neidanId", value = "内丹ID", required = true)
			@NotBlank(message = "内丹" + CustomMessages.ID_NOT_NULL) String neidanId) {
		List<String> list = chongwuNeidanService.selectResonates(neidanId);

		return JsonResult.success(null, list);
	}

	@ApiOperation("查询宠物的全部内丹")
	@RequestMapping(value = "/selectNeidans", method = RequestMethod.GET)
	public JsonResult<List<ChongwuNeidanVO>> selectNeidans(ChongwuNeidanDTO neidanDTO) {
		List<ChongwuNeidanVO> list = chongwuNeidanService.selectNeidans(neidanDTO);

		return JsonResult.success(null, list);
	}

}